package com.stt.order.design.factory;

import com.stt.order.design.strategy.impl.DiscountPromotionStrategy;
import com.stt.order.design.strategy.impl.FullReductionStrategy;
import com.stt.order.design.strategy.impl.HolidayDoublePointsStrategy;
import com.stt.order.design.strategy.impl.UserTypePromotionStrategy;
import com.stt.order.model.Order;
import com.stt.order.design.strategy.PromotionStrategy;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;

/**
 * 促销策略工厂
 * 负责创建促销策略链
 */
@Component
public class PromotionStrategyFactory {
    
    /**
     * 创建促销策略链
     * @param order 订单
     * @return 促销策略列表
     */
    public List<PromotionStrategy> createPromotionChain(Order order) {
        // 将促销类型字符串分割成列表（支持多个促销类型，用逗号分隔）
        List<String> promotionTypes = Arrays.asList(order.getPromotionType().split(","));
        // 策略实现类集合
        List<PromotionStrategy> strategies = new ArrayList<>();
        
        // 首先添加用户类型优惠策略（这是基础折扣）
        strategies.add(new UserTypePromotionStrategy());
        
        // 然后添加其他促销类型优惠策略
        for (String promotionType : promotionTypes) {
            switch (promotionType) {
                case "FULL_REDUCTION" -> strategies.add(new FullReductionStrategy());
                case "DISCOUNT" -> strategies.add(new DiscountPromotionStrategy());
                case "HOLIDAY_DOUBLE_POINTS" -> strategies.add(new HolidayDoublePointsStrategy());
            }
        }
        
        return strategies;
    }
} 